package com.itheima.htmo_01.exception;


import cn.hutool.core.util.ObjectUtil;
import com.itheima.htmo_01.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){

        e.printStackTrace();

        String message = ObjectUtil.isNotEmpty(e.getMessage()) ? e.getMessage() : "操作失败";

        return Result.error(message);
    }
}
